!> 演示单维度自由落体运动 <br>
!> 方法: 速度 verlet
program main

    use verlet_m, only: velocity_verlet
    implicit none
    integer, parameter :: nstep = 11
    real :: t(nstep), y(nstep, 1), v(nstep, 1), a(nstep, 1)
    integer :: i

    call velocity_verlet(fcn, [0.0, 1.0], [0.0], [0.0], t, y, v, a)

    write (*, *) "演示单维度自由落体运动: "
    write (*, 100) "时间", "位移", "速度", "加速度"

    open (1, file="plot/verlet.csv", form="formatted", status="unknown")
    write (1, 100) "时间", "位移", "速度", "加速度"

    do i = 1, nstep
        write (*, 100) t(i), y(i, 1), v(i, 1), a(i, 1)
        write (1, 100) t(i), y(i, 1), v(i, 1), a(i, 1)
    end do

    close (1)

100 format(*(g12.3, :, ',', 2x))

contains

    !> 自由落体运动
    pure subroutine fcn(y, a)
        real, intent(in) :: y(:)   !! 位置
        real, intent(out) :: a(:)  !! 加速度
        a = -9.8
    end subroutine fcn

end program main
